/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

package xowl.interpreter.frontends.functional;

/**
 *
 * @author Laurent WOUTERS
 */
public class VariableLoader {
    public static xowl.lang.actions.CodeVariable load(FNode node, xowl.interpreter.frontends.LexicalContext context) {
        if (node.getType() == FNodeType.CodeVar)
            return load_CodeVariable((FCodeVar)node, context);
        if (node.getType() == FNodeType.Element) {
            FElementNode elem = (FElementNode)node;
            String name = elem.getName();
            if (name.equals(xowl.interpreter.frontends.VocActions.expCodeVariable))
                return load_CodeVariable(elem, context);
        }
        return null;
    }
    private static xowl.lang.actions.CodeVariable load_CodeVariable(FCodeVar node, xowl.interpreter.frontends.LexicalContext context) {
        String var = node.getValue();
        return context.resolveCode(var);
    }
    private static xowl.lang.actions.CodeVariable load_CodeVariable(FElementNode node, xowl.interpreter.frontends.LexicalContext context) {
        String var = ((FLiteralNode)node.getChildren().get(0)).getLexicalForm();
        return context.resolveCode(var);
    }
}
